const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();

// 查询数据库集合云函数入口函数
exports.main = async (event, context) => {
  // 返回数据库查询结果
  // console.log(event.data)
  const personalKeyInformation = await db.collection('personalKeyInformation').where({
    openId: event.data,
  }).get()
  const evaluation = await db.collection('evaluation').where({
    openId: event.data,
  }).get()
  const education = await db.collection('education').where({
    openId: event.data,
  }).orderBy('enrolText', 'desc').get()
  const workExperience = await db.collection('workExperience').where({
    openId: event.data,
  }).orderBy('entryText', 'desc').get()
  const project = await db.collection('project').where({
    openId: event.data,
  }).orderBy('entryText', 'desc').get()
  const qualificationCertificate = await db.collection('qualificationCertificate').where({
    openId: event.data,
  }).get()

  return {
    personalKeyInformation: personalKeyInformation.data[0],
    evaluation: evaluation.data[0],
    education: education.data,
    workExperience: workExperience.data,
    project: project.data,
    qualificationCertificate: qualificationCertificate.data,
  };
};
